/**
 * OverView: 游戏数据规整、清洗与裁减
 * Author: Zhaomi
 * Date: 13-5-13 下午8:06
 * Email: yanyuetian@gmail.com
 * Create By JetBrains WebStorm.
 */
var Convert = require("../utils/convert.js");

exports.listSlice = function(allGames){
    var reslist = [];
    for(var i = 0;i < allGames.length;i++){
        var gameInfo = allGames[i].game;
        var pkginfo = allGames[i].gpkg || {};
        var currOut = {
            "gameId": gameInfo.id,
            "gameName": gameInfo.shortName || gameInfo.name,
            "gameLogo": gameInfo.logourl,
            "statusText": gameInfo.issimple ? gameInfo.category : gameInfo.operationStatus,
            "downloadCount": Convert.getShortNum(gameInfo.downstatTotal),
            "scoreSet": Convert.getScoreAry(gameInfo.avrgScore),
            "pkgSize": Convert.byteUnit(pkginfo.fileSize),
            "commentCount": gameInfo.commentTotal,
            "detectResult": "下载",
            "version": gameInfo.version
        };
        reslist[reslist.length] = currOut;
    }
    return {"glist": reslist};
};

exports.articleSlice = function(dobj){
    var resObj = {};
    resObj.title = dobj.title;
    resObj.date = dobj.modifyTime.toString();
    resObj.content = Convert.htmlDecode(dobj.content);
    return resObj;
};

exports.extendPkginfo = function(gameinfo, pkginfo){
    if(!pkginfo || !gameinfo)
        return pkginfo;
    if("undefined" == typeof(pkginfo["playType"])){
        pkginfo["playType"] = 1;
    }
    pkginfo["gameId"] = gameinfo.id;
    pkginfo["gameName"] = gameinfo.name;
    pkginfo["logoImagePath"] = gameinfo.logourl && gameinfo.logourl.replace("_","");
    pkginfo["gameType"] = gameinfo.issimple? 0:1;
    pkginfo["category"] = gameinfo.category;
    pkginfo["versionCode"] = pkginfo["orgVersionCode"];
    return pkginfo;
};